# Contributor (MSYS2): David Macek <david.macek.0@gmail.com>
# Maintainer (Arch Linux): Alexander Rødseth <rodseth@gmail.com>
# Contributor (Arch Linux): Angel Velasquez <angvp@archlinux.org>
# Contributor (Arch Linux): Ionut Biru  <ibiru@archlinux.ro>
# Contributor (Arch Linux): William Rea <sillywilly@gmail.com>
# Contributor (Arch Linux): Allan McRae <mcrae_allan@hotmail.com>

_realname=geany
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.36.0
pkgrel=2
pkgdesc='Fast and lightweight IDE (mingw-w64)'
arch=('any')
url='https://www.geany.org/'
license=('GPL')
depends=("${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-adwaita-icon-theme"
         "${MINGW_PACKAGE_PREFIX}-python3")
makedepends=('perlxml'
             'intltool'
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python3-docutils")
optdepends=("${MINGW_PACKAGE_PREFIX}-geany-plugins: various extra features")
install="${_realname}-${CARCH}.install"
source=(#https://download.geany.org/${_realname}-${pkgver}.tar.bz2{,.sig}
        ${_realname}-${pkgver}.tar.gz::https://github.com/geany/geany/archive/${pkgver}.tar.gz
        "0001-Fix-windres-invocation.patch" # we don't yet have prefixed windres sadly
        "0002-Use-FHS.patch") # even upstream says FIXME :)
validpgpkeys=('ACA0246889FB96B63382111724CCD8550E5D1CAE'
              '457990C86F91F33DE05EBF1BCC03633F700990F2')
sha256sums=('fb5af274c75509d9104a3fc4c0dfc070b9cebebcaaffdfe1d1410684bf42ac30'
            '9f5781f0ac781dcbad74dd5ac7c56f5991dbe98c681dc7560f9edff88f633311'
            'd5928b6afb63590657e9a242285396a44dc2bab7e58fed4e34272937210a923e')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # Python2 fix
  sed -i '0,/on/s//on2/' data/templates/files/main.py

  # Syntax highlighting for PKGBUILD files
  sed -i 's/Sh=/Sh=PKGBUILD;/' data/filetype_extensions.conf
  
  patch -p1 -i "${srcdir}/0001-Fix-windres-invocation.patch"
  patch -p1 -i "${srcdir}/0002-Use-FHS.patch"
  
  NOCONFIGURE=1 ./autogen.sh
}

build() {
  mkdir -p "build-${MINGW_CHOST}"
  cd "build-${MINGW_CHOST}"

  # libiberty
  export LDFLAGS+=" -L${MINGW_PREFIX}/lib/binutils"

  # config.h
  export PLUGIN_CFLAGS+=" -I$(pwd)"

  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-gtk3 \
    --disable-pdf-docs \
    --disable-api-docs

  make
}

package() {
  cd "build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  rm -r "${pkgdir}${MINGW_PREFIX}/share/applications"
  rm -r "${pkgdir}${MINGW_PREFIX}/share/icons/hicolor/index.theme"
}
